package com.tencent.sr.iris.basic.saas.restapi.approval;

import com.tencent.sr.iris.basic.service.interfaces.client.approval.ApprovalProcessClient;
import com.tencent.sr.iris.basic.service.interfaces.request.approval.ProcessTaskListRequest;
import com.tencent.sr.iris.basic.service.interfaces.request.approval.RevokeProcessRequest;
import com.tencent.sr.iris.basic.service.interfaces.response.approval.ProcessDetailResponse;
import com.tencent.sr.iris.basic.service.interfaces.response.approval.ProcessTaskListResponse;
import com.tencent.sr.rmall.common.primitive.HttpResult;
import com.tencent.sr.rmall.springbootstarter.authtoken.localbean.AppUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api("审批流程控制")
@RequestMapping("/iris/basic/saas/v1/approvalProcess")
public class ApprovalProcessController {

    @Resource
    private ApprovalProcessClient approvalProcessClient;
    @Resource
    private AppUser appUser;

    @PostMapping("/taskList")
    @ApiOperation("任务列表")
    public HttpResult<ProcessTaskListResponse> taskList(@RequestBody @Validated ProcessTaskListRequest request) {
        return approvalProcessClient.taskList(request);
    }

    @PostMapping("/revoke")
    @ApiOperation("撤销流程")
    public HttpResult<ProcessDetailResponse> revoke(@RequestBody @Validated RevokeProcessRequest request) {
        request.setSaasId(appUser.getSaasId());
        request.setUid(appUser.getUid());
        return approvalProcessClient.revoke(request);
    }

}
